package com.tvunetworks.center.user.controller.api;

import com.tvunetworks.center.common.util.Result;
import com.tvunetworks.center.common.util.ResultUtil;
import com.tvunetworks.center.user.model.param.api.PageRunningInstanceIdsParam;
import com.tvunetworks.center.user.service.UserInstanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Etan Yang
 * @create: 2021/11/10 9:20
 */

@RestController
@RequestMapping(value  = {"uniformapi/${openApiVersion}/instance", "openapi/${openApiVersion}/instance"})
public class InstanceApiController {
    @Autowired
    private UserInstanceService userInstanceService;

    /**
     * 分页获取正在执行的instanceId
     * @param param 参数
     * @return 返回正在执行的instanceId
     */
    @PostMapping("/pageRunningInstance")
    public Result pageRunningInstanceIds(@RequestBody PageRunningInstanceIdsParam param) {
        if (param.getPageNum() == 0) {
            param.setPageNum(1);
        }
        if (param.getPageSize() == 0) {
            param.setPageSize(50);
        }
        return ResultUtil.success(userInstanceService.pageRunningInstanceIds(param));
    }

    /**
     * 获取查询instanceId对应的信息
     * @param instanceIds instanceIds
     * @return 返回查询instanceId对应的信息
     */
    @PostMapping("getInstanceMessage")
    public Result getInstanceMessage(@RequestBody List<String> instanceIds) {
        return ResultUtil.success(userInstanceService.getInstanceMessage(instanceIds));
    }
}